package ysq.xyg.base.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author yu sheng qiang
 * @create 2017-03-27 16:43
 **/
public class ProProperties {
    private static final String resource = "/pro.properties";
    private Properties prop = new Properties();
    public static ProProperties instance = new ProProperties();

    public static ProProperties getInstance() {
        return instance;
    };

    private ProProperties() {
        String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
        InputStream stream = null;
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            stream = classLoader.getResourceAsStream(stripped);
        }
        if (stream == null) {
            stream = ProProperties.class.getResourceAsStream(resource);
        }
        if (stream == null) {
            stream = ProProperties.class.getClassLoader().getResourceAsStream(stripped);
        }
        if (stream != null) {
            try {
                prop.load(stream);
            } catch (IOException e) {
                // TODO
            }
        }
    }


    //保存路径
    public String getBaseUploadURL() {
        return prop.getProperty("baseUploadURL");
    }
    //图片路径
    public String getPictureURL() {
        return prop.getProperty("pictureURL");
    }


    //微信oauth获取openid通用接口
    public String getWxOauthAcceptOpenidURL() {
        return prop.getProperty("wxOauthAcceptOpenidURL");
    }

    //#微信oauth获取通用接口
    public String getWxOauthURL(String state) {
        return prop.getProperty("wxOauthURL")+state;
    }


    //微信oauth跳转到首页面接口
    public String getWxOauthRredirectIndexURL(String memberId) {
        return prop.getProperty("wxOauthRredirectIndexURL")+memberId;
    }

    //微信oauth跳转到我的页面接口
    public String getWxPayRequestURL(){
        return prop.getProperty("wxPayRequestURL");
    }

    //秘钥地址
    public String getKeyAddress(){
        return prop.getProperty("keyAddress");
    }
}
